<template>
    <el-main>
        <el-main class="ep-body">
            <epl-top-bar :datas="{formData:form}" showPerson psTagType="PERSON_AAB001_GROUP"
                         personType="PERSON_AAC031_12">
            </epl-top-bar>
            <epl-userMessage dataType="person" idCount="2">
            </epl-userMessage>
            <el-card class="ep-card">
                <ep-title>死亡人员信息</ep-title>
                <el-form :model="form" ref="form" :rules="rules">
                    <el-row :gutter="10">
                        <ep-date colspan="8" placeholder="请选择死亡日期" label="死亡日期" format="yyyyMM" rules="this.$rules.test_noBlank" name="aae138" :property="form.aae138"
                                 p="R"  :datas="{formData:form}"></ep-date>
                        <ep-input  colspan="8" label="建国前老工人标识" name="aac081" :property="form.aac081" p="D"
                                  :datas="{formData:form}"></ep-input>
                    </el-row>
                </el-form>
                <ep-title>供养人员基本信息</ep-title>
                <ep-table :data="tableData1" edited="true" >
                    <ep-table-column editor="text" name="aac002" header="社会保障号"></ep-table-column>
                    <ep-table-column editor="text" name="aac003" header="姓名"></ep-table-column>
                    <ep-table-column editor="text" name="aac004" header="性别"></ep-table-column>
                    <ep-table-column editor="text" name="bic108" header="户粮关系"></ep-table-column>
                    <ep-table-column editor="text" name="aac006" header="出生日期"></ep-table-column>
                    <ep-table-column editor="text" name="aae144" header="供养关系"></ep-table-column>
                    <ep-table-column editor="text" name="aac086" header="孤寡标识"></ep-table-column>
                    <ep-table-column editor="text" name="bic109" header="是否散失劳动能力"></ep-table-column>
                </ep-table>
                <el-form :model="form"  :rules="rules">
                    <el-row type="flex" justify="center">
                        <ep-saveButton id="doSave" type="primary" top="20" bottom="20" ref="save" @formValidate="formValidate"
                                       :validate="['form']"
                                       :datas="{formData: form,panel:panel}"></ep-saveButton>
                    </el-row>
                </el-form>
            </el-card>
        </el-main>
    </el-main>
</template>
<script type="es6">
    export default {
        data() {
            return {
                form:{
                    aae138: {
                        value: '',
                        p: 'R'
                    },
                    aac081: {
                        value: '',
                        p: 'D'
                    },

                },
                tableData1: {},
                panel: {},

                rules:{
                    aae138: [
                        {required: true, validator: this.$rules.test_noBlank, trigger: 'blur'}

                    ],

                },
                codeTypes:{

                },
                codeTypeFilters:{

                },
                pager: {
                    page: 1,
                    size: 10
                },
                total: 0,
            }
        },
        computed: {
            functionId() {
                if (this.$store.getters.init.path !== this.$route.path) return;
                if (this.$store.getters.init.mdParam === null || this.$store.getters.init.mdParam === undefined) return;
                if (this.$store.getters.init.mdParam.functionid === undefined) return;
                return this.$store.getters.init.mdParam.functionid;
            },
            backFun() {
                return this.$store.getters.backFun;
            },
            init_formData() {
                if (this.$store.getters.init.path !== this.$route.path)  return;
                return this.$store.getters.init.form;
            },
            doInitformData: {
                get: function () {
                    if (this.$store.getters.common === null) return [];
                    if (this.$store.getters.common.path !== this.$route.path) return;
                    return this.$store.getters.common.formData;
                },
                set: function (newValue) {
                    if (newValue.path !== this.$route.path) return;
                    return newValue;
                }
            },
            init_panel() {
                if (this.$store.getters.init.path !== this.$route.path)  return;
                return this.$store.getters.init.panel;
            },
            doInitpanel: {
                get: function () {
                    if (this.$store.getters.common === null) return [];
                    if (this.$store.getters.common.path !== this.$route.path) return;
                    return this.$store.getters.common.panel;
                },
                set: function (newValue) {
                    if (newValue.path !== this.$route.path) return;
                    return newValue;
                }
            },

        },
        created() {
            let param = {
                path: this.$route.path,
                codeTypes:this.codeTypes,
                codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
                form:this.form,
                tableData1:this.tableData1,
                panel:this.panel

            };
            if (this.$route.query.keepAlive === undefined) {
                this.$store.dispatch('SET_INIT', param);
            }
        },
        watch: {
            init_formData: {
                handler(value) {
                    if (value == undefined) return;
                    this.getformData(value);
                },
                deep: true
            },
            doInitformData: {
                handler(value) {
                    if (value == undefined) return;
                    this.getformData(value);
                },
                deep: true
            },
            init_panel: {
                handler(value) {
                    if (value == undefined) return;
                    this.getpanel(value);
                },
                deep: true
            },
            doInitpanel: {
                handler(value) {
                    if (value == undefined) return;
                    this.getpanel(value);
                },
                deep: true
            },

            backFun: {
                handler(value) {
                    if (value === null) return;
                    this.customBackFun();
                    let backFun = [];
                    backFun = value.split(',');
                    if (backFun.indexOf('rDoInit') >= 0) {
                        let codeTypes = {

                        };
                        let form = {
                            aae138: {
                                value: '',
                                p: 'R'
                            },
                            aac081: {
                                value: '',
                                p: 'D'
                            },

                        };
                        let tableData1= {};
                        let panel= {};

                        let param = {
                            path: this.$route.path,
                            codeTypes:codeTypes,
                            codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
                            form:form,
                            tableData1:tableData1,
                            panel:panel

                        };
                        this.$store.dispatch('SET_INIT', param);
                    }
                }
            }
        },
        mounted() {
            if (this.$store.getters.cacheData === null) return;
            if (this.$store.getters.cacheData[this.$route.path] === undefined)  return;
            if (this.$store.getters.cacheData[this.$route.path].path !== this.$route.path) return;
            if (this.$store.getters.cacheData[this.$route.path].form !== undefined) {
                this.getformData(this.$store.getters.cacheData[this.$route.path].form);
            }
            if (this.$store.getters.cacheData[this.$route.path].panel !== undefined) {
                this.getpanel(this.$store.getters.cacheData[this.$route.path].panel);
            }

        },
        beforeRouteLeave(to, from, next) {
            let param = {
                path: this.$route.path,
                codeTypes: this.$store.getters.codeTypes,
                codeTypeFilters: window.btoa(JSON.stringify(this.codeTypeFilters)),
                form:this.form,
                tableData1:this.tableData1,
                panel:this.panel

            };
            if (from) {
                this.$store.dispatch('SET_CACHEDATA', param);
            }
            next();
        },
        methods: {
            getformData(value) {
                this.form = value;
            },
            getpanel(value) {
                this.panel = value;
            },


            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
            },
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`);
            },
            handleEdit(id) {
                this.dialogFormVisible = true;
            },
            formValidate(value){
                if(value && value.length>0){
                    let btn = true;
                    value.forEach((item,index)=>{
                        if(!btn) return
                        this.$refs[item].validate((valid) => {
                            if (valid) {
                                btn = true;
                            } else {
                                btn = false;
                            }
                        });
                    })
                    if(btn) this.$refs.save.btn();
                }
            },

            customBackFun(){//自定义方法体
            },
        },
    }
</script>
